<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
    <h1>修改商品页面</h1>
    <input type="text" v-model="p.id" placeholder="id" readonly>
    <input type="text" v-model="p.title" placeholder="标题">
    <input type="text" v-model="p.num" placeholder="库存">
    <input type="text" v-model="p.price" placeholder="价格">
    <input type="button" value="修改" @click="update()">
</div>
<!--引入Vue框架-->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!--引入Axios框架-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script>
    let v = new Vue({
        el:"body>div",
        data:{
            p:{
                id:"",
                title:"",
                num:"",
                price:""
            }
        },
        methods:{
            update(){
                axios.post("/update",v.p).then(function () {
                    alert("修改完成!");
                    //回到列表页面
                    location.href = "/select.html";
                })
            }
        },
        created:function () {
            //  localhost:8080/selectById?id=5
            //location.search 得到  ?id=5
            axios.get("/selectById"+location.search).then(function (response) {
                //得到通过id查询到的商品对象 赋值给Vue里面的对象,页面会自动改变
                v.p = response.data;
            })
        }
    })
</script>
</body>
</html>